<?php
require_once("environment.php");
//Admins only!
if(!$acc->isLogged()) die(change_site("account.php"));
//The submenus...
$temp->currentPage("Home >> Account >> Delete Account");
$temp->addSubMenu("Create Account", "createAccount.php");
$temp->addSubMenu("Change Password", "editAccount.php");
$temp->addSubMenu("Delete Account", "deleteAccount.php");
$temp->addSubMenu("Logout", "account.php?action=Logout");
//This selects the account tab and then the create account tab...
$temp->addCSS("th {text-align: center;}");
$temp->setTab(9, 2);
$temp->generate();

if(!fixArr($_GET, "who")){
    $sql = $db->Execute("SELECT * FROM `monster`.`admins` WHERE `sysAdmin` != 1");
    if($sql->RecordCount() > 0){
        print "<table width=\"100%\">\n<tr>\n<th>Name</th>\n<th>Last Login</th>\n<th>Delete</th>\n</tr>\n";
        while($row = $sql->FetchRow()){
            if($row['Last Login'] == null){
                $lastLogin = "Never";
            }else{
                $lastLogin = date("F jS, Y", $row['Last Login']);
            }
            $dirtyName = urlencode($row['Name']);
            print "<tr>\n<td style=\"text-align: center;\">{$row['Name']}</td>\n<td style=\"text-align: center;\">{$lastLogin}</td>\n<td style=\"text-align: center;\"><a href=\"deleteAccount.php?who={$dirtyName}\" style=\"text-decoration: underline;\">Delete</a></td>\n</tr>";
        }
        print "</table>";
    }else{
        print "No non-system admins found.";
    }
}else{
    $who = fixArr($_GET, "who");
    if($acc->adminExists($who)){
        if(fixArr($_GET, "conf") != "true"){
            print "Are you SURE you want to delete {$who}? This decision is final and cannot be undone.<br />\n<br />\n";
            print "<a href=\"deleteAccount.php\" style=\"text-decoration: underline;\">No, bring me back to the delete page.</a><br />\n<br />\n";
            print "<a href=\"deleteAccount.php?who=".urlencode($who)."&conf=true\" style=\"text-decoration: underline;\">Yes, delete them.</a>";
        }else{
            if($acc->deleteAdmin($who)){
                print "The admin was successfully deleted.";
            }else{
                print "There was an error in the system.<br />\nPlease try again later.";
            }
        }
    }else{
        change_site("deleteAccount.php");
    }
}
?>
